total sales in array c++ two dimensional array

75

total sales in array c++ two dimensional array -

view sourceprint?
01
#include <iostream>
02
using std::cin;
03
using std::cout;
04
using std::endl;
05
 
06
#include <conio.h>
07
 
08
#include <iomanip>
09
using std::fixed;
10
using std::setw;
11
using std::setprecision;
12
using std::showpoint;
13
 
14
int main()
15
{
16
    const static int PEOPLE = 5; //number of sales people (4)
17
    const static int PRODUCTS = 6;  //number of different products (5)
18
 
19
    int sales[5][6] = {{1, 2, 3, 4}, {1, 2, 3, 4, 5}};
20
    double value;
21
    double totalSales;
22
    double productSales[PRODUCTS] = {0.0};
23
    int salesPerson;
24
    int product;
25
 
26
    cout << " Enter the salesperson's number (1-4), the product number (1-5), and total product sales.\n "
27
         << "Enter -1 for salesperson to end input.\n";
28
    cin >> salesPerson;
29
 
30
    while (salesPerson != -1)
31
    {
32
        cin >> product >> value;
33
 
34
            value++;
35
         
36
        cin >> salesPerson;
37
    }
38
 
39
    cout << "\nThe total sales for each salesperson are displayed at the "
40
        << "end of each row,\n" << "and the total sales for each product "
41
        << "are displayed at the bottom of each column.\n " << setw( 12 )
42
        << 1 << setw( 12 ) << 2 << setw( 12 ) << 3 << setw( 12 ) << 4
43
        << setw( 12 ) << 5 << setw( 13 ) << "Total\n" << fixed << showpoint;
44
 
45
    for (int i = 1; i < 4; i++)
46
    {
47
        totalSales = 0.0;
48
        cout << i;
49
 
50
        for (int j = 1; j < 5; j++)
51
        {
52
            ++totalSales;
53
 
54
            cout << setw (12) << setprecision (2) << sales [i][j];
55
 
56
            += productSales;
57
        }
58
 
59
        cout << setw (12) << setprecision (2) << totalSales << '\n';
60
   }
61
 
62
    cout << "\nTotal" << setw( 8 ) << setprecision( 2 )
63
      << productSales[ 1 ];
64
 
65
   // display total product sales
66
   for ( int j = 2; j < totalSales; j++ )
67
      cout << setw( 12 ) << setprecision( 2 ) << productSales[ j ];
68
 
69
   cout << endl;
70
    
71
   _getch();
72
}

total sales in array c++ two dimensional array -

#include <iostream> 
using std::cin; 
using std::cout; 
using std::endl; 
using std::ios;

#include <iomanip>
using std::fixed;
using std::setw; 
using std::setprecision; 
using std::showpoint;

int main()
{
   const int PEOPLE = 5;
   const int PRODUCTS = 6;
  
   int sales[5][6]={{1},{2},{3},{4}};
   double value;
   double totalSales;
   double productSales[ PRODUCTS ] = { 0.0 };
   int salesPerson;
   int product;
   
   
   cout << "Enter the salesperson (1 - 4), product number (1 - 5), and "
        << "total sales.\nEnter -1 for the salesperson to end input.\n";
   cin >> salesPerson;
   
   while ( salesPerson != -1 ) 
   {
      cin >> product >> value;
      
	  value++;
      cin >> salesPerson;
   } // end while

   cout << "\nThe total sales for each salesperson are displayed at the "
        << "end of each row,\n" << "and the total sales for each product "
        << "are displayed at the bottom of each column.\n " << setw( 12 ) 
        << 1 << setw( 12 ) << 2 << setw( 12 ) << 3 << setw( 12 ) << 4 
        << setw( 12 ) << 5 << setw( 13 ) << "Total\n" << fixed << showpoint;

   for ( int i = 1; i < 4; i++ ) 
   {
      totalSales = 0.0;
      cout << i;
      
      for ( int j = 1; j < 5; j++ ) 
      {
		  ++ totalSales;

         cout << setw( 12 ) << setprecision( 2 ) << sales[ i ][ j ];
         
		  += productSales ;
      } // end for

      cout << setw( 12 ) << setprecision( 2 ) << totalSales << '\n';
   } // end for
   
   cout << "\nTotal" << setw( 8 ) << setprecision( 2 ) 
      << productSales[ 1 ];

   // display total product sales
   for ( int j = 2; j < totalSales; j++ )
      cout << setw( 12 ) << setprecision( 2 ) << productSales[ j ];

   cout << endl;
   return 0; // successful termination
} // end main

Comments

Submit
0 Comments